﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO_HealthInsurance;

namespace DAO_HealthInsurance
{
   public class DAOPolicies:ConnectDatabase
    {
        public SqlCommand Cmd;
        public DTOPolicies objPo;
        public DataTable ListPolicy()
        {
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("ListPolicy", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("Policies");
                da.Fill(dt);
                CloseConnect();
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public int InsertPolicy(DTOPolicies objPo)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("InsertPolicy", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyName", SqlDbType.VarChar, 50).Value = objPo.PolicyName;
                Cmd.Parameters.Add("@PolicyDesc", SqlDbType.VarChar, 150).Value = objPo.PolicyDescription;
                Cmd.Parameters.Add("@Amount", SqlDbType.Float).Value = objPo.PolicyAmount;
                Cmd.Parameters.Add("@Emi", SqlDbType.Float).Value = objPo.PolicyEmi;
                Cmd.Parameters.Add("@CompanyId", SqlDbType.Int).Value = objPo.CompanyId;
                Cmd.Parameters.Add("@MedicalId", SqlDbType.VarChar, 50).Value = objPo.MedicalId;
              
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;
        }

        public int DeletePolicy(DTOPolicies objPo)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("DeletePolicy", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPo.PolicyId;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }
        public int UpdatePolicyInfo(DTOPolicies objPo)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("UpdatePolicyInfo", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPo.PolicyId;
                Cmd.Parameters.Add("@PolicyName", SqlDbType.VarChar, 50).Value = objPo.PolicyName;
                Cmd.Parameters.Add("@PolicyDesc", SqlDbType.VarChar, 150).Value = objPo.PolicyDescription;
                Cmd.Parameters.Add("@Amount", SqlDbType.Float).Value = objPo.PolicyAmount;
                Cmd.Parameters.Add("@Emi", SqlDbType.Float).Value = objPo.PolicyEmi;
                Cmd.Parameters.Add("@CompanyId", SqlDbType.Int).Value = objPo.CompanyId;
                Cmd.Parameters.Add("@MedicalId", SqlDbType.VarChar, 50).Value = objPo.MedicalId;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }

        public DataTable GetpolicyById(DTOPolicies objPo)
        {
            try
            {
                Cmd = new SqlCommand("GetpolicyById", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPo.PolicyId;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("Policies");
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
    }
}
